﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:host="clr-namespace:ViewOnCore.HostContract"
    xmlns:wpf="clr-namespace:ViewOnCore.Helper.WPF">

    <Style x:Key="FolderBrowserDialog.TreeViewItem" TargetType="{x:Type TreeViewItem}">
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeViewItem}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <ToggleButton
									  x:Name="Expander"
									  Style="{StaticResource ExpandCollapseToggleStyle}"
									  IsChecked="{Binding Path=IsExpanded,RelativeSource={RelativeSource TemplatedParent}}"
									  ClickMode="Press"/>
                        <!-- Background -->
                        <Border Name="highlight" Grid.Column="1" Margin="1" BorderBrush="{DynamicResource VOColor1A}" CornerRadius="1" BorderThickness="1" Background="{DynamicResource VOColor17}" Opacity="0">
                            <Border.BitmapEffect>
                                <OuterGlowBitmapEffect GlowColor="{Binding Source={x:Static host:Host.UIService}, Path=GlowColors.VOGColor1A}" GlowSize="2" Noise="0" Opacity="0.5" />
                            </Border.BitmapEffect>
                        </Border>
                        
                        <Border
												  Name="Border"
												  Grid.Column="1"
												  Margin="2,2,2,2"
												  CornerRadius="1">
                            <StackPanel Orientation="Horizontal">
                                
                                <!-- Content -->
                                <Image Name="imgIcon"
                                       Source="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                                                                                        AncestorType={x:Type TreeViewItem}},
                                                        Path=(wpf:FBDItemProperties.IconUri)}" 
                                       Width="16"
                                       Height="16"
                                       Stretch="Fill"
                                       VerticalAlignment="Center" />

                                <!-- Content -->
                                <ContentPresenter
														  x:Name="PART_Header"
														  ContentSource="Header"
														  Margin="2,2,2,2"
														  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />

                                <!-- Loading... -->
                                <StackPanel
                                    Name="spLoading"
                                    Orientation="Horizontal"
                                    Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
                                                                            AncestorType={x:Type TreeViewItem}}, 
                                                                            Path=(wpf:FBDItemProperties.IsLoading),
                                                                            Converter={x:Static wpf:ConverterBoolToVisiblity.Instance}}">
                                    <Grid Height="16"  MinWidth="50" MaxWidth="75" Margin="5,0" >
                                        <ProgressBar Name="pbLoading" Height="13"  MinWidth="50" MaxWidth="75" IsIndeterminate="True" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                        <TextBlock Name="txtLoading" Text="Loading..." FontSize="8.6" Margin="5,0" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                    </Grid>
                                </StackPanel>

                            </StackPanel>
                            <Border.Triggers>
                                <EventTrigger RoutedEvent="Mouse.MouseEnter">
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <Storyboard.Children>
                                                <DoubleAnimation To="0.7" Duration="00:00:00.2000000" Storyboard.TargetName="highlight" Storyboard.TargetProperty="Opacity" />
                                            </Storyboard.Children>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                                <EventTrigger RoutedEvent="Mouse.MouseLeave">
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <Storyboard.Children>
                                                <DoubleAnimation To="0" Duration="00:00:00.2000000" Storyboard.TargetName="highlight" Storyboard.TargetProperty="Opacity" />
                                            </Storyboard.Children>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                            </Border.Triggers>
                        </Border>
                        
                        <!-- Child items -->
                        <ItemsPresenter
									  x:Name="ItemsHost"
									  Grid.Row="1"
									  Grid.Column="1"
									  Grid.ColumnSpan="2" Margin="-3,0,0,0"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="false">
                            <Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed"/>
                        </Trigger>
                        <Trigger Property="HasItems" Value="false">
                            <Setter TargetName="Expander" Property="Visibility" Value="Hidden"/>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter TargetName="Border" Property="Background" Value="{DynamicResource VOColor02}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>